package top.xylweb.workflow.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.xylweb.user.entity.User;
import top.xylweb.workflow.entity.ReAttend;
import top.xylweb.workflow.service.ReAttendServiceImpl;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("reAttend")
public class ReAttendController {

    @Autowired
    private ReAttendServiceImpl reAttendService;

    /**
     *@Author JackWang [www.coder520.com]
     *@Date 2017/7/1 22:48
     *@Description 补签数据页面
     */
    @RequestMapping("/")
    public String toReAttend(Model model, HttpSession session){

        User user = (User) session.getAttribute("userinfo");
        List<ReAttend> reAttendList = reAttendService.listReAttend(user.getUsername());
        model.addAttribute("reAttendList",reAttendList);
        return "reAttend";
    }

    @RequestMapping("/start")
    public void startReAttendFlow(@RequestBody ReAttend reAttend, HttpSession session){
//        User user = (User)session.getAttribute("userinfo");
//        reAttendService.
        reAttend.setReAttendStarter("diandian");
        reAttendService.startReAttendFlow(reAttend);
    }

    @RequestMapping("/list")
    @ResponseBody
    public List<ReAttend> listReAttendFlow(){
        String userName = "lingdao";
        List<ReAttend> tasks =  reAttendService.listTasks(userName);
        return tasks;
    }

    @RequestMapping("/approve")
    public void approveReAttendFlow(@RequestBody ReAttend reAttend){

        reAttendService.approve(reAttend);
    }

}
